package com.sx.zongzhi.adapter;


import android.content.Context;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sx.zongzhi.R;
import com.sx.zongzhi.bean.EducationBean;
import com.sx.zongzhi.widget.NoScrollGridView;

import java.util.List;

/**
 * Created by XZY on 2017/12/4.
 * 学历选择的adapter
 */

public class EducationSelectAdapter extends BaseQuickAdapter<EducationBean,BaseViewHolder> {

    private Context context;
    EducationCallback mCallback;

    public EducationSelectAdapter(Context context, @LayoutRes int layoutResId, @Nullable List<EducationBean> data) {
        super(layoutResId, data);
        this.context=context;
    }

    @Override
    protected void convert(BaseViewHolder helper, final EducationBean item) {
        helper.setText(R.id.tv_Title,item.getName());
        NoScrollGridView gridView=helper.getView(R.id.gridView);
        if (item.getSchoolings()!=null&&item.getSchoolings().size()>0) {
            EducationListAdapter adapter = new EducationListAdapter(context, R.layout.item_event_type_list, item.getSchoolings());
            gridView.setAdapter(adapter);
            adapter.getEducation(new EducationListAdapter.EducationCallback() {
                @Override
                public void getData(EducationBean.SchoolingsBean schoolingsBean) {
                    if (mCallback != null) {
                        mCallback.getData(schoolingsBean);
                    }
                }
            });
        }
    }

    /**
     * 定义一个接口
     */
    public interface EducationCallback {
        void getData(EducationBean.SchoolingsBean schoolingsBean);
    }

    /*接口回调*/
    public void getEducation(EducationCallback callback) {
        mCallback = callback;
    }
}
